# Dual_Axis_Laser:
#   vertical axis: servo
#   horizontal axis:stepper_motor
#

import RPi.GPIO as GPIO
from time import sleep

from .servo_pigpio import Servo
from .stepper_motor import  Stepper_Motor

class Dual_Axis_Laser:
    LEFT = 0
    RIGHT = 1
    UP = 2
    DOWN = 3

    def __init__(self, stepper_in1,stepper_in2,stepper_in3, stepper_in4, Vertical__Pin,Vertical_init_angle):
        self.horizontal_stepper_motor = Stepper_Motor(stepper_in1,stepper_in2,stepper_in3, stepper_in4)
        self.vertical_servo=Servo(Vertical__Pin,Vertical_init_angle)
        self.DICT_CMD_ACTION = {Dual_Axis_Laser.LEFT: self.turn_left,
                                Dual_Axis_Laser.RIGHT: self.turn_right,
                                Dual_Axis_Laser.UP: self.turn_up,
                                Dual_Axis_Laser.DOWN: self.turn_down
                                }
        self.each_step_angle = 5

    def turn_left(self):
        self.horizontal_stepper_motor.action(Stepper_Motor.CLOCKWISE)

    def turn_right(self):
        self.horizontal_stepper_motor.action(Stepper_Motor.ANTICLOCKWISE)

    def turn_up(self):
        self.vertical_servo.turn_clockwise(self.each_step_angle)

    def turn_down(self):
        self.vertical_servo.turn_anti_clockwise(self.each_step_angle)
 
    def action(self, cmd_to_dual_axis):
        self.DICT_CMD_ACTION[cmd_to_dual_axis]()
